﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace Adams.Shared
{
    public static class CalendarHelper
    {
        public static string GetHijriDate(DateTime d)
        {
            HijriCalendar myCal = new HijriCalendar();
            string m = string.Empty;
            switch (myCal.GetMonth(d))
            {
                case 1:
                    m = "Muharram";
                    break;
                case 2:
                    m = "Safar";
                    break;
                case 3:
                    m = "Rabi' al-Awwal";
                    break;
                case 4:
                    m = "Rabi' al-Thani";
                    break;
                case 5:
                    m = "Jumada al-Awwal";
                    break;
                case 6:
                    m = "Jumada al-Thani";
                    break;
                case 7:
                    m = "Rajab";
                    break;
                case 8:
                    m = "Sha'aban";
                    break;
                case 9:
                    m = "Ramadan";
                    break;
                case 10:
                    m = "Shawwal";
                    break;
                case 11:
                    m = "Dhu al-Qi'dah";
                    break;
                case 12:
                    m = "Dhu al-Hijjah";
                    break;
            }

            string ret = m + " " + myCal.GetDayOfMonth(d).ToString() + ", " + myCal.GetYear(d).ToString();
            return ret;
        }

        public static string GetShortHijriDate(DateTime d)
        {
            HijriCalendar myCal = new HijriCalendar();
            string m = string.Empty;
            switch (myCal.GetMonth(d))
            {
                case 1:
                    m = "Muh";
                    break;
                case 2:
                    m = "Saf";
                    break;
                case 3:
                    m = "Rba";
                    break;
                case 4:
                    m = "Rbt";
                    break;
                case 5:
                    m = "Jua";
                    break;
                case 6:
                    m = "Jut";
                    break;
                case 7:
                    m = "Raj";
                    break;
                case 8:
                    m = "Sha";
                    break;
                case 9:
                    m = "Ram";
                    break;
                case 10:
                    m = "Shaw";
                    break;
                case 11:
                    m = "Qid";
                    break;
                case 12:
                    m = "Hij";
                    break;
            }

            string ret = m + " " + myCal.GetDayOfMonth(d).ToString();
            return ret;
        }

        public static string GetMonthName(int month)
        {
            switch (month)
            {
                case 1:
                    return "January";
                case 2:
                    return "February";
                case 3:
                    return "March";
                case 4:
                    return "April";
                case 5:
                    return "May";
                case 6:
                    return "June";
                case 7:
                    return "July";
                case 8:
                    return "August";
                case 9:
                    return "September";
                case 10:
                    return "October";
                case 11:
                    return "November";
                case 12:
                    return "December";
                default:
                    return "";
            }
        }

        public static bool IsMonthHijri(string month)
        {
            if (string.IsNullOrEmpty(month))
            {
                return false;
            }

            if (
                Adams.Shared.Str.IsEqual("January", month) ||
                Adams.Shared.Str.IsEqual("February", month) ||
                Adams.Shared.Str.IsEqual("March", month) ||
                Adams.Shared.Str.IsEqual("April", month) ||
                Adams.Shared.Str.IsEqual("May", month) ||
                Adams.Shared.Str.IsEqual("June", month) ||
                Adams.Shared.Str.IsEqual("July", month) ||
                Adams.Shared.Str.IsEqual("August", month) ||
                Adams.Shared.Str.IsEqual("September", month) ||
                Adams.Shared.Str.IsEqual("October", month) ||
                Adams.Shared.Str.IsEqual("November", month) ||
                Adams.Shared.Str.IsEqual("December", month))
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        public static string GetHijriMonthName(int month)
        {
            switch (month)
            {
                case 1:
                    return "Muharram";
                case 2:
                    return "Safar";
                case 3:
                    return "Rabi' al-Awwal";
                case 4:
                   return "Rabi' al-Thani";
                case 5:
                   return "Jumada al-Awwal";
                case 6:
                    return "Jumada al-Thani";
                case 7:
                    return "Rajab";
                case 8:
                    return "Sha'aban";
                case 9:
                    return "Ramadan";
                case 10:
                    return "Shawwal";
                case 11:
                    return "Dhu al-Qi'dah";
                case 12:
                    return  "Dhu al-Hijjah";
                default:
                    return "";
            }
        }

        public static string GetShortMonthName(int month)
        {
            switch (month)
            {
                case 1:
                    return "Jan";
                case 2:
                    return "Feb";
                case 3:
                    return "Mar";
                case 4:
                    return "Apr";
                case 5:
                    return "May";
                case 6:
                    return "Jun";
                case 7:
                    return "Jul";
                case 8:
                    return "Aug";
                case 9:
                    return "Sep";
                case 10:
                    return "Oct";
                case 11:
                    return "Nov";
                case 12:
                    return "Dec";
                default:
                    return "";
            }
        }

        public static string GetShortHijriMonthName(int month)
        {
            switch (month)
            {
                case 1:
                    return "Mhm";
                case 2:
                    return "Sfr";
                case 3:
                    return "Rba";
                case 4:
                    return "Rbt";
                case 5:
                    return "Jmu";
                case 6:
                    return "Jmt";
                case 7:
                    return "Rjb";
                case 8:
                    return "Shb";
                case 9:
                    return "Rmd";
                case 10:
                    return "Shw";
                case 11:
                    return "Dhq";
                case 12:
                    return "Dhh";
                default:
                    return "";
            }
        }

        public static int GetMonthID(string month)
        {
            switch (month.ToLower())
            {
                case "january":
                    return 1;
                case "february":
                    return 2;
                case "march":
                    return 3;
                case "april":
                    return 4;
                case "may":
                    return 5;
                case "june":
                    return 6;
                case "july":
                    return 7;
                case "august":
                    return 8;
                case "september":
                    return 9;
                case "october":
                    return 10;
                case "november":
                    return 11;
                case "december":
                    return 12;
                default:
                    return 0;
            }
        }

        public static int GetHijriMonthID(string month)
        {
            switch (month.ToLower())
            {
                case "muharram":
                    return 1;
                case "safar":
                    return 2;
                case "rabi' al-awwal":
                    return 3;
                case "rabi' al-thani":
                    return 4;
                case "jumada al-awwal":
                    return 5;
                case "jumada al-thani":
                    return 6;
                case "rajab":
                    return 7;
                case "sha'aban":
                    return 8;
                case "ramadan":
                    return 9;
                case "shawwal":
                    return 10;
                case "dhu al-hi'dah":
                    return 11;
                case "dhu al-hijjah":
                    return 12;
                default:
                    return 0;
            }
        }
    }
}